package com.yiqi.zhiyuan.feature.mine.view.adapter;

import android.view.View;
import android.widget.CompoundButton;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.framework.AM;
import com.yiqi.zhiyuan.R;
import com.yiqi.zhiyuan.entity.enums.CarPassType;
import com.yiqi.zhiyuan.entity.vo.CarVO;

/**
 * @ProjectName: ZhiYuan
 * @Description: java类作用描述
 * @Author: lijuwen
 * @CreateDate: 2019/3/22 9:48
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/3/22 9:48
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class VehicleAdapter extends BaseQuickAdapter<CarVO, BaseViewHolder> {
    CompoundButton.OnCheckedChangeListener listener;
    private boolean isCheck = false;
    private boolean isCheckALL = false;
    private int mCheckPosition=-1;


    public VehicleAdapter() {
        super(R.layout.item_vehicle_manage);
    }

    @Override
    protected void convert(BaseViewHolder helper, CarVO item) {
        AM.image().bind(item.getCarImg(), helper.getView(R.id.img_vehicle));
        helper.setText(R.id.tv_vehicle_name, item.getCarName())
                .setText(R.id.tv_vehicle_model, item.getCarModelNo())
                .setText(R.id.tv_vehicle_number, item.getCarNo())
                .setChecked(R.id.cb_check, isCheckALL)
                .addOnClickListener(R.id.view_show_used)
                .addOnClickListener(R.id.tv_vehicle_adopt)
                .setVisible(R.id.view_show_used, item.getIsPass() == 2)
                .setImageResource(R.id.iv_show_used,mCheckPosition == helper.getAdapterPosition()?R.mipmap.ic_car_uncheck:R.mipmap.ic_car_checked)
                .setText(R.id.tv_vehicle_adopt, CarPassType.getName(item.getIsPass()))
                .setTextColor(R.id.tv_vehicle_adopt, item.getIsPass() == 2 ? mContext.getResources().getColor(R.color.primary_comparison) : mContext.getResources().getColor(R.color.color_red))
                .setOnCheckedChangeListener(R.id.cb_check, listener)
                .setTag(R.id.cb_check, item);

        if (isCheck) {
            if (item.getIsUse()==0){
                helper.getView(R.id.cb_check).setVisibility(View.VISIBLE);
            }else {
                helper.getView(R.id.cb_check).setVisibility(View.INVISIBLE);
            }

        } else {
            helper.getView(R.id.cb_check).setVisibility(View.GONE);
        }
    }

    public void setCheck(boolean isCheck) {
        this.isCheck = isCheck;
        notifyDataSetChanged();
    }


    public void setCheckAll(boolean isCheckALL) {
        this.isCheckALL = isCheckALL;
        notifyDataSetChanged();
    }


    public void setCheckListener(CompoundButton.OnCheckedChangeListener listener) {
        this.listener = listener;
    }

    public void checkState(int position) {
        this.mCheckPosition = position;
        notifyDataSetChanged();
    }
}
